package com.wenwei.paper.activity;

import android.content.SharedPreferences;

import com.jaeger.library.StatusBarUtil;
import com.wenwei.paper.R;
import com.wenwei.paper.base.BaseActivity;
import com.wenwei.paper.base.Constant;
import com.wenwei.paper.bean.UserLoginBean;
import com.wenwei.paper.utils.RogerSPUtils;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.functions.Action1;

/**
 * Created by Administrator on 2017/7/13.
 */
public class SplashActivity extends BaseActivity {
    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initView() {
        super.initView();
        StatusBarUtil.setTranslucent(this, 30);
    }

    @Override
    protected void initData() {
        super.initData();

        Observable.just("").delay(3, TimeUnit.SECONDS).subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                SharedPreferences sharedPreferences = getSharedPreferences("configuration", 0);
                String name = sharedPreferences.getString("is_first","");
                if(name==null || name.equals("")){
                    goActivity(mContext,GuideActivity.class);
                }else{
                    UserLoginBean ub = RogerSPUtils.getObject(mContext, Constant.SP_USER_LOGIN_RESULT,UserLoginBean.class);
                    if(ub == null){
                        goActivity(mContext,LoginActivity.class);
                    }else {
                        goActivity(mContext,HostActivity.class);
                    }
                }
                finish();

            }
        });
    }
}
